﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
	CodeFile="ExportSIUI.aspx.cs" Inherits="ExportSIUI" Title="ExportSIUI" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<%@ Register Namespace="NS_Controls" TagPrefix="cc1" %>
<%@ Register Namespace="CustomControlsNS" TagPrefix="cc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderContent" runat="Server">
	<asp:UpdatePanel ID="upSIUI" runat="server">
		<ContentTemplate>
			<div id="divExportSIUI" runat="server" style="height: 100%; overflow: auto; display: block;">
				<table width="98%">
					<tr>
						<td>
							<div class="menu_th">
								<table>
									<tr>
										<td>
											<asp:Label ID="lblExportSIUI" runat="server" CssClass="menu_th1">Export SIUI</asp:Label>
										</td>
										<td>
											<asp:UpdateProgress ID="UpdateProgressExportSIUI" runat="server" DisplayAfter="100">
												<ProgressTemplate>
													<span id="spnProgress" class="clsTextBoldYellow">(<% =Resources.GridView.PageLoading %>)</span>
												</ProgressTemplate>
											</asp:UpdateProgress>
										</td>
									</tr>
								</table>
							</div>
							<table width="100%">
								<tr>
									<td style="width: 15%" class="tdn">
										<asp:Literal ID="dummyControl1" runat="server" Text="<%$ Resources:DatabaseStrings, FromSIUI%>" />
									</td>
									<td style="width: 15%" class="tdn">
										<span class="tdSmall">
											<asp:TextBox ID="txtStart_Date" runat="server" CssClass="box" MaxLength="10" />
											<asp:ImageButton ID="imgCalStart" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png"
												BorderWidth="0" Width="16" Height="16" Style="position: relative; top: 0; left: 0;" />
											<ajaxToolKit:FilteredTextBoxExtender ID="filter_StartDate" runat="server" TargetControlID="txtStart_Date"
												ValidChars="-/.0123456789" />
											<ajaxToolKit:CalendarExtender ID="calDataStart" runat="server" TargetControlID="txtStart_Date" PopupButtonID="imgCalStart" />
											<ajaxToolKit:CalendarExtender ID="calDataStartOnFocus" runat="server" TargetControlID="txtStart_Date" />
										</span>
									</td>
									<td style="width: 15%" class="tdn">
										<asp:Literal ID="dummyControl2" runat="server" Text="<%$ Resources:DatabaseStrings, ToSIUI%>" />
									</td>
									<td style="width: 15%" class="tdn">
										<span class="tdSmall">
											<asp:TextBox ID="txtEnd_Date" runat="server" CssClass="box" MaxLength="10" />
											<asp:ImageButton ID="imgDataEnd" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png"
												BorderWidth="0" Width="16" Height="16" Style="position: relative; top: 0; left: 0;" />
											<ajaxToolKit:FilteredTextBoxExtender ID="filter_EndDate" runat="server" TargetControlID="txtEnd_Date"
												ValidChars="-/.0123456789" />
											<ajaxToolKit:CalendarExtender ID="calDataEnd" runat="server" TargetControlID="txtEnd_Date" PopupButtonID="imgDataEnd" />
											<ajaxToolKit:CalendarExtender ID="calDataEndOnFocus" runat="server" TargetControlID="txtEnd_Date" />
										</span>
									</td>
								</tr>
								<tr>
									<td style="width: 15%" class="tdn">
										Tip Export:
									</td>
									<td style="width: 15%" class="tdn">
										<span class="tdSmall">
											<asp:DropDownList ID="drpTypes" runat="server" AutoPostBack="true" OnSelectedIndexChanged="On_SelectedIndexChanged"
												Width="350px" />
										</span>
									</td>
									<td style="width: 15%" class="tdn">
										Item export:
									</td>
									<td style="width: 15%" class="tdn">
										<span class="tdSmall">
											<asp:DropDownList ID="drpItems" runat="server" Width="350px" />
										</span>
									</td>
								</tr>
								<tr id="trSalarizare" runat="server">
									<td style="width: 15%" class="tdn">
										<asp:Literal ID="periodIdText" runat="server" Text="Period ID:" />
									</td>
									<td style="width: 15%" class="tdn">
										<span class="tdSmall">
											<asp:DropDownList ID="drpPeriod" runat="server" Width="350px" />
										</span>
									</td>
									<td style="width: 15%" class="tdn">
										<asp:Literal ID="insurerIdText" runat="server" Text="Insurer ID:" />
									</td>
									<td style="width: 15%" class="tdn">
										<span class="tdSmall">
											<asp:DropDownList ID="drpInsurer" runat="server" Width="350px" />
										</span>
									</td>
								</tr>
								<tr id="tr1" runat="server">
									<td style="width: 15%" class="tdn">
										<label for="<% =chkValidation.ClientID %>">
											<asp:Literal ID="ValidationText" runat="server" Text="Cu validare:" />
										</label>
									</td>
									<td style="width: 15%" class="tdn" colspan="3">
										<span class="tdSmall">
											<asp:CheckBox ID="chkValidation" runat="server" />
										</span>
									</td>
								</tr>
								<tr>
									<td style="width: 15%" class="tdn" colspan="4">
										<cc2:CustomButton ID="btnExport" runat="server" Text="<%$ Resources:DatabaseStrings, ExportSIUI %>"
											OnServerClick="btnExportSIUI_Click" OnClick="exportStart();" />
									</td>
								</tr>
							</table>
							<div class="divEndTotal">
							</div>
						</td>
					</tr>
				</table>
			</div>
			<asp:Literal ID="output" runat="server" />
			<br />
			<fieldset style="padding: 2px 2px 2px 2px;">
				<legend title=""><% =Resources.DatabaseStrings.HistorySIUI%>:</legend>
				<div>
					<table style="width: 98%">
						<tr>
							<td>
								<asp:Panel ID="pnGridDetails" runat="server" Visible="true" CssClass="clsText">
									<asp:DataGrid ID="HistoryGrid" runat="server" AutoGenerateColumns="False"
										AllowPaging="True" PageSize="10" PagerStyle-HorizontalAlign="Right" PagerStyle-Mode="NumericPages"
										OnPageIndexChanged="MyDataGrid_Page"
										AllowSorting="true" OnSortCommand="MyDataGrid_Sort"
										OnItemCreated="HistoryGrid_ItemCreated"
										AlternatingItemStyle-BackColor="#eeeeee" HeaderStyle-BackColor="#aaaadd"
										BackColor="White" ForeColor="Black" BorderWidth="1" BorderColor="black"
										Font-Size="10pt" Font-Name="Verdana" CellSpacing="0" CellPadding="3" GridLines="Both">
										<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#4A3C8C"></HeaderStyle>
										<ItemStyle BackColor="#DEDFDE"></ItemStyle>
										<Columns>
											<asp:BoundColumn DataField="Id" HeaderText="Id" SortExpression="Id"></asp:BoundColumn>
											<asp:BoundColumn DataField="UserHipo" HeaderText="UserHipo" SortExpression="UserHipo" />
											<asp:BoundColumn DataField="ExportDate" HeaderText="DateExport" SortExpression="ExportDate" DataFormatString="{0:yyyy-MM-dd HH:mm}<sup><u>{0:ss}</u></sup>" />
											<asp:BoundColumn DataField="center" HeaderText="TypeExport" SortExpression="center" />
											<asp:BoundColumn DataField="StartDate" HeaderText="StartDate" SortExpression="StartDate" DataFormatString="{0:yyyy&#8209;MM&#8209;dd}" />
											<asp:BoundColumn DataField="EndDate" HeaderText="EndDate" SortExpression="EndDate" DataFormatString="{0:yyyy&#8209;MM&#8209;dd}" />
											<asp:HyperLinkColumn HeaderText="FileName" DataNavigateUrlField="FileName" DataNavigateUrlFormatString="~/Tools/ExportXML.ashx?file={0}"
												DataTextField="FileName" SortExpression="FileName" />
										</Columns>
									</asp:DataGrid>
								</asp:Panel>
							</td>
							<td align="right" valign="top">
								<span id="spanTrace"></span>
							</td>
						</tr>
					</table>
				</div>
			</fieldset>
		</ContentTemplate>
	</asp:UpdatePanel>
	<ajaxToolKit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="pnlPopup"
		PopupControlID="pnlPopup" BackgroundCssClass="modalBackground" />
	<asp:Panel ID="pnlPopup" runat="server" CssClass="updateProgress" Style="display: none">
		<div align="center" style="margin-top: 13px; width:200px">
			<img src="../../Images/Hipocrate/rotator.gif" alt="" /><br />
			<span class="updateProgressMessage">Se genereaza exportul ...</span><br />
			<span id="spanTimer"></span>
		</div>
	</asp:Panel>
	<script language="javascript" type="text/javascript">
		var g_str_mdlPopup = '<%=mdlPopup.ClientID %>';
		var g_str_spanTimer = 'spanTimer';
		var g_str_spanTrace = 'spanTrace';
		
		var delayTimer = 1000;
		var timer = null;

		function exportStart() {
			$find(g_str_mdlPopup).show();
			$get(g_str_spanTrace).innerHTML = '';
			StartTheTimer();
			writeTrace('<img src="../../Images/Hipocrate/check.gif" alt="" />Initializare export.<br/>');
		}

		function hideModal() {
			$find(g_str_mdlPopup).hide();
			StopTheTimer();
			writeTrace('<img src="../../Images/Hipocrate/check.gif" alt="" />Exportul s-a realizat in:<br />' + $get(g_str_spanTimer).innerHTML);
		}

		var startUpTime;
		function StartTheTimer() {
			startUpTime = new Date();
			$get(g_str_spanTimer).innerHTML = '';
			timer = window.setInterval("getTime()", delayTimer);
		}

		function StopTheTimer() {
			clearTimeout(timer);
		}

		function getTime() {
			var spanTimer = $get(g_str_spanTimer);

			var time = new Date();
			var diff = (time.getHours() - startUpTime.getHours()) * 3600 + time.getMinutes() * 60 + time.getSeconds() - startUpTime.getMinutes() * 60 - startUpTime.getSeconds();
			var curr_sec = diff % 60;
			var curr_min = (diff - curr_sec) / 60;
			spanTimer.innerHTML = curr_min + " : " + (curr_sec < 10 ? '0' : '') + curr_sec;
		}

		function writeTrace(log) {
			var spanTrace = $get(g_str_spanTrace);
			spanTrace.innerHTML += log;
		}

		function onGetdataSuccess(response) {
			var spanTrace = $get(g_str_spanTrace);
			spanTrace.innerHTML += response;
		}

		function onGetdataFail(result, userContext, methodName) {
			var error = "Method: " + methodName + "\nTimeout: " + result.get_timedOut() + "\nMessage: " + result.get_message();
			alert(error);
		}
	</script>
</asp:Content>
